from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.pt")  # pretrained YOLO11n model

# Run batched inference on a list of images
results = model("D:/python/v8_mine/dataset")  # return a list of Results objects 白近、白远、黑近、黑远均无误判

# Process results list
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    obb = result.obb  # Oriented boxes object for OBB outputs
    class_ids = boxes.cls.cpu().numpy().astype(int)
    if 67 in class_ids:  # 检测到手机
        result.save(filename='./image_cellphone/result_')  # 保存
        print("检测到手机，已经保存")